package com.easy.project.controller.system;

import com.easy.project.base.result.BizResult;
import com.easy.project.domain.dto.auth.LoginDTO;
import com.easy.project.domain.vo.system.SysAuthVO;
import com.easy.project.service.system.ISysAuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wxz
 * @since 2024-01-10
 */
@RestController
@RequestMapping("/sys-auth")
@Api(tags = "系统管理-鉴权")
public class SysAuthController {

    @Resource
    private ISysAuthService sysAuthService;

    /**
     * 生成public key
     * @return
     */
    @GetMapping("/generate/public/key")
    @ApiOperation(value = "生成public key")
    public BizResult<String> generateRsaPublicKey(){
        return BizResult.success(sysAuthService.generateRsaPublicKey());
    }

    /**
     * 登录
     * @return
     */
    @PostMapping("/login")
    @ApiOperation(value = "登录",notes = "返回token")
    public BizResult<SysAuthVO> login(@RequestBody @Validated LoginDTO loginDTO){
        return BizResult.success(sysAuthService.login(loginDTO));
    }


    /**
     * 登出
     * @return
     */
    @PostMapping("/login/out")
    @ApiOperation(value = "登出")
    public BizResult<Void> loginOut(){
        sysAuthService.loginOut();
        return BizResult.success();
    }
}
